using System;
using UnityEngine;

namespace InventorySystem
{
    [Serializable]
    public class ItemStack 
    {
        [SerializeField]
        private ItemDifinition _item;

        [SerializeField]
        private int _numberOfItems;

        public bool IsStackable => _item.IsStackable;

        public int NumberOfItems
        { 
            get => _numberOfItems;
            set 
            {
                value = value < 0 ? 0 : value;
                _numberOfItems = _item != null && _item.IsStackable ? value : 1;
            }
        }

        public ItemDifinition Item
        {
            get => _item;
            set 
            {
                _item = value;
            }
        }

        public ItemStack(ItemDifinition item, int numberOfItems)
        {
            _item = item;
            NumberOfItems = numberOfItems;
        }

        public ItemStack() { }
    }
}